/**
 * Company : SIANGKLOM.
 * Created By : Chatree Siangklom
 * Created On : Oct 4, 2013  3:05:26 PM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : sap.business.commons
 * File Name : SapStructure.java
 * TODO
 */
package sap.business.commons;

import java.io.IOException;

import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoStructure;
import com.sap.conn.jco.JCoTable;

import sap.jco.client.Connection;

/**
 * @author Chatree Siangklom of Administrator
 * Date =Oct 4, 2013 : 3:05:26 PM 
 * CreateBy=Chatree Siangklom
 * 
 * SapStructure
 * TODO
 */
public class SapStructure {
	private String sap_structure;
	private JCoFunction jCoFunction;

	/**
	 * @return the sap_structure
	 * Date =Oct 4, 2013 : 3:05:52 PM 
	 * CreateBy=Chatree Siangklom
	 * SapStructure.java String
	 * TODO
	 */
	public String getSap_structure() {
		return sap_structure;
	}


	/**
	 * Date =Oct 4, 2013 : 3:05:26 PM 
	 * CreateBy=Chatree Siangklom
	 * SapStructure
	 * TODO
	 */
	public SapStructure(String sap_structure) {
		this.sap_structure = sap_structure;
	}
	
	public SapStructure(String sap_structure, JCoFunction jCoFunction) {
		this.jCoFunction = jCoFunction;
		this.sap_structure = sap_structure;
	}
	
	/**
	 * 
	 * Date =Oct 4, 2013 : 5:32:03 PM 
	 * CreateBy=Chatree Siangklom
	 * JCoStructure
	 * TODO
	 * @return
	 * @throws JCoException
	 * @throws IOException
	 * @throws Exception
	 */
	public JCoStructure getJCoStructure() throws JCoException, IOException, Exception {
		if(jCoFunction == null) 
			throw new Exception("SAP Connection is null !!!");
		
		JCoStructure structure = jCoFunction.getTableParameterList().getStructure(getSap_structure());
		
		if(structure == null)
			throw new Exception("SAP Structure "+ getSap_structure() +" is null or isEmpty !!!");
		
		return structure;
	}

}
